﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DTO;
namespace DAO
{
    public class DAOQuocGia:DataProvider
    {
        public static DataTable DSQG()
        {
            SqlConnection MoKetNoi = KetNoi();
            string chuoilenh = "select * from quocgia";
            SqlDataAdapter da = new SqlDataAdapter(chuoilenh, MoKetNoi);
            DataTable danhsachQG;
            DataSet ds = new DataSet();
            da.Fill(ds);
            danhsachQG = ds.Tables[0];
            DongKetNoi();
            return danhsachQG;
        }
        public static int ThemQG(DTOQuocGia qg)
        {
            SqlConnection MoKetNoi = KetNoi();
            string chuoilenh = "insert into quocgia(maqg,tenqg) values(@ma,@ten)";
            SqlCommand lenh = new SqlCommand(chuoilenh, MoKetNoi);
            SqlParameter values = new SqlParameter("@ma", qg.MaQG);
            lenh.Parameters.Add(values);
            values = new SqlParameter("@ten", qg.TenQG);
            lenh.Parameters.Add(values);
            int result = lenh.ExecuteNonQuery();
            DongKetNoi();
            return result;
        }
        public static int SuaQG(DTOQuocGia qg, string macu)
        {
            SqlConnection MoKetNoi = KetNoi();
            string chuoilenh = "update quocgia set maqg=@ma, tenqg=@ten where maqg=@maqg";
            SqlCommand lenh = new SqlCommand(chuoilenh, MoKetNoi);
            SqlParameter values = new SqlParameter("@ma", qg.MaQG);
            lenh.Parameters.Add(values);
            values = new SqlParameter("@ten", qg.TenQG);
            lenh.Parameters.Add(values);
            values = new SqlParameter("@maqg", macu);
            lenh.Parameters.Add(values);
            int result = lenh.ExecuteNonQuery();
            DongKetNoi();
            return result;
        }
        public static int XoaQG(string ma)
        {
            SqlConnection MoKetNoi = KetNoi();
            string chuoilenh = "delete from quocgia where maqg=@ma";
            SqlCommand lenh = new SqlCommand(chuoilenh, MoKetNoi);
            SqlParameter values = new SqlParameter("@ma", ma);
            lenh.Parameters.Add(values);
            int result = lenh.ExecuteNonQuery();
            DongKetNoi();
            return result;
        }
    }
}
